# Dockerfile
FROM python:3.10-slim

ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 安装系统依赖
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
    cifs-utils \
    iputils-ping \
    kmod && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 创建挂载点
RUN mkdir -p /mnt/smt1/laser /mnt/smt1/spi /mnt/smt1/aoi \
    /mnt/smt2/laser /mnt/smt2/spi /mnt/smt2/aoi /mnt/automation/eol \
    /mnt/assembly/eol

# 配置 CIFS
RUN echo "insecure_smb1_enabled=true" >> /etc/cifs-utils/cifscreds.conf && \
    mkdir -p /etc/modprobe.d && \
    echo "options cifs enable_legacy_dialects=1" > /etc/modprobe.d/cifs.conf

# 创建应用目录
WORKDIR /app

# 安装 Python 依赖
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 暴露端口
EXPOSE 5001

# 启动脚本
RUN printf '#!/bin/sh\n\
# 挂载共享文件夹\n\
mount -t cifs "//172.27.40.136/mes" /mnt/smt1/laser -o username=yy,password=wW123456,vers=3.0,iocharset=utf8\n\
mount -t cifs "//172.27.40.72/lujing" /mnt/smt1/spi -o username=sinic-tek,password=sinictek,sec=ntlmssp,iocharset=utf8\n\
mount -t cifs "//172.27.40.37/Eagle3D_data" /mnt/smt1/aoi -o username=yy,password=wW123456,sec=ntlmssp,iocharset=utf8\n\
mount -t cifs "//172.27.40.88/Laser" /mnt/smt2/laser -o username=yy,password=wW123456,vers=3.0,iocharset=utf8\n\
mount -t cifs "//172.27.40.102/Res" /mnt/smt2/spi -o username=sinictek,password=sinictek,vers=3.0,iocharset=utf8\n\
mount -t cifs "//172.27.40.94/Mes" /mnt/smt2/aoi -o username=sinictek,password=sinictek,vers=3.0,iocharset=utf8\n\
mount -t cifs "//172.27.41.84/ProcessData" /mnt/automation/eol -o username=yy,password=wW123456,vers=3.0,iocharset=utf8\n\
mount -t cifs "//172.27.41.106/Data" /mnt/assembly/eol -o username=yy,password=wW123456,vers=3.0,iocharset=utf8\n\
\n\
# 运行 Python 应用\n\
cd /app\n\
python run.py\n' > /start.sh

RUN chmod +x /start.sh

ENTRYPOINT ["/start.sh"]
